package com.bloom.opensourceframework.retrofit.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bloom.opensourceframework.R;
import com.bloom.opensourceframework.retrofit.model.GirlEntity;
import com.bloom.opensourceframework.widget.RatioImageView;
import com.bumptech.glide.Glide;

import java.util.List;


/**
 * Created by bloom on 2018/5/28.
 */

public class GirlsAdapter extends RecyclerView.Adapter<GirlsAdapter.ViewHolder> {

    private List<GirlEntity> mGirls;
    private Context mContext;

    public GirlsAdapter(Context context, List<GirlEntity> girlLists) {
        this.mContext = context;
        this.mGirls = girlLists;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_retrofit_girl_layout_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        GirlEntity result = mGirls.get(position);

        Glide.with(mContext)
                .load(result.getUrl())
                .centerCrop()
                .into(holder.girlView);
//                .getSize((width, height) -> {
//                    if (!viewHolder.card.isShown()) {
//                        viewHolder.card.setVisibility(View.VISIBLE);
//                    }
//                });

    }

    @Override
    public int getItemCount() {
        return mGirls != null ? mGirls.size() : 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private RatioImageView girlView;

        public ViewHolder(View itemView) {
            super(itemView);
            girlView = (RatioImageView) itemView.findViewById(R.id.riv_girl);
            girlView.setOriginalSize(50, 50);
        }

    }


}
